{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "False Positive Rate (FPR): 0.05288922404544927\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "\n",
    "# Matrix string\n",
    "matrix_string = \"\"\"\n",
    "          0         1         2\n",
    "0  600004.0      20.0       0.0\n",
    "1     303.0  599802.0     319.0\n",
    "2       0.0     310.0  599242.0\n",
    "\"\"\"\n",
    "\n",
    "# Convert string to array format\n",
    "lines = matrix_string.strip().split('\\n')\n",
    "confusion_matrix = []\n",
    "for line in lines[1:]:\n",
    "    row = [float(val) for val in line.split()[1:]]\n",
    "    confusion_matrix.append(row)\n",
    "\n",
    "confusion_matrix = np.array(confusion_matrix)\n",
    "\n",
    "\n",
    "# True negatives (TN) are diagonal elements\n",
    "TN = np.diag(confusion_matrix)\n",
    "\n",
    "# False positives (FP) are the sum of all values in columns excluding the diagonal\n",
    "FP = confusion_matrix.sum(axis=0) - TN\n",
    "\n",
    "# False Positive Rate (FPR)\n",
    "FPR = FP / (FP + TN)\n",
    "FPR = np.nan_to_num(FPR, nan=0.0)\n",
    "# print(\"False Positive Rate (FPR):\", FPR)\n",
    "FPR = 100*(sum(FPR)/len(FPR))\n",
    "print(\"False Positive Rate (FPR):\", FPR)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "HITL",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.15"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
